using System;
using System.Collections.Generic;
using System.Text;

using System.Data;
using System.IO;
using System.CodeDom.Compiler;
using System.CodeDom;
using Microsoft.CSharp;
using System.Data.SqlClient;
using System.Reflection;
using System.Diagnostics;
using System.Xml;

namespace ESBSimpleSamples.ServiceClient.Generator.Scripts
{
    /// <summary>
    ///
    /// </summary>
    public abstract class XmlScript : ScriptBase
    {
        #region Abstract instance methods

        protected abstract void WriteTo(XmlWriter writer); 

        #endregion

        #region Protected instance methods

        protected void OutputXml()
        {
            using (StringWriter writer = new StringWriter())
            {
                XmlTextWriter xmlWriter = new XmlTextWriter(writer);
                xmlWriter.Indentation = 2;
                xmlWriter.IndentChar = ' ';
                xmlWriter.Formatting = Formatting.Indented;
                this.WriteTo(xmlWriter);
                xmlWriter.Flush();
                //HACK -es, the indent code does not inject CRs:
                string output = writer.GetStringBuilder().ToString();
                output.Replace(@">", string.Format(@">{0}", Environment.NewLine));
                this.Output.Write(output);
            }
            this.Output.Close();
        }

        #endregion

        #region Public instance methods

        public override string Language
        {
            get { return "xml"; }
        }

        #endregion

    }
}